//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Controls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using FormLabel = CommunityServer.ControlPanel.Controls.FormLabel;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.Galleries.Options
{
	/// <summary>
	/// Summary description for PostOptionsPage.
	/// </summary>
	public class PostOptionsPage : BaseGalleryPage
	{

		#region Child Controls

		protected StatusMessage Status;
		protected YesNoRadioButtonList ynEnableRepliesOverride;
		protected YesNoRadioButtonList ynEnableOrderPrintsOverride;
        protected YesNoRadioButtonList ynEnableRatingsOverride;
        protected YesNoRadioButtonList ynEnableTrackbacksOverride;
		protected CommentModerationDropDownList ModerationDDLOverride;
		protected DropDownList ExpiredDays;
		protected ResourceLinkButton SaveButton;

		#endregion

        override protected void OnInit(EventArgs e)
        {
            this.Load += new System.EventHandler(this.Page_Load);
            this.SaveButton.Click += new EventHandler(SaveButton_Click);
            base.OnInit(e);
        }

        
        private void Page_Load(object sender, EventArgs e)
		{
  
			if(!IsPostBack)
            {
    
                ynEnableRepliesOverride.SelectedValue = CurrentGallery.EnableCommentsOverride;
                ynEnableRatingsOverride.SelectedValue = CurrentGallery.EnableRatingsOverride;
                ynEnableTrackbacksOverride.SelectedValue = CurrentGallery.EnableTrackbacksOverride;
				ynEnableOrderPrintsOverride.SelectedValue = CurrentGallery.EnableOrderPrintsOverride;

				ListItem li = ModerationDDLOverride.Items.FindByValue(CurrentGallery.ModerationTypeOverride.ToString());
                if(li != null)
                    li.Selected = true;

				ExpiredDays.Items.Add(new ListItem(Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Always"), "999999"));
				ExpiredDays.Items.Add(new ListItem("90 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "90"));
				ExpiredDays.Items.Add(new ListItem("60 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "60"));
				ExpiredDays.Items.Add(new ListItem("30 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "30"));
				ExpiredDays.Items.Add(new ListItem("14 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "14"));
				ExpiredDays.Items.Add(new ListItem("7 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "7"));
				ExpiredDays.Items.Add(new ListItem("6 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "6"));
				ExpiredDays.Items.Add(new ListItem("5 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "5"));
				ExpiredDays.Items.Add(new ListItem("4 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "4"));
				ExpiredDays.Items.Add(new ListItem("3 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "3"));
				ExpiredDays.Items.Add(new ListItem("2 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "2"));
				ExpiredDays.Items.Add(new ListItem("1 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "1"));
				ExpiredDays.Items.Add(new ListItem(ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_DisableNewComments"), "0"));
				li = ExpiredDays.Items.FindByValue(CurrentGallery.CommentExpirationDays.ToString());
                if(li != null)
                    li.Selected = true;
            }
		}

        private void SaveButton_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {

                
                CurrentGallery.EnableCommentsOverride = ynEnableRepliesOverride.SelectedValue;
                CurrentGallery.EnableRatingsOverride = ynEnableRatingsOverride.SelectedValue;
                CurrentGallery.EnableTrackbacksOverride = ynEnableTrackbacksOverride.SelectedValue;
				CurrentGallery.EnableOrderPrintsOverride = ynEnableOrderPrintsOverride.SelectedValue;

                CurrentGallery.ModerationTypeOverride = (CommentModerationType) Enum.Parse(typeof(CommentModerationType),ModerationDDLOverride.SelectedValue);
                CurrentGallery.CommentExpirationDays = Int32.Parse(ExpiredDays.SelectedValue);

            	CommunityServer.Galleries.Galleries.Update(CurrentGallery);

				Status.Success = true;
				// Status.Text = "Your changes have been saved successfully";
				Status.Visible = true;

            }
        }



    }
}
